package com.origon.entities;

import static javax.persistence.CascadeType.ALL;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Transient;


/**
 * The persistent class for the product database table.
 * 
 */
@Entity
public class Product implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private String id;

	private String brand;

	private String code;
	
	private String description;

	private Date createdDateInShop;

	private Date lastModifiedDate;

	private Date manufacturedDate;
	
	private Date expiryDate;

	private String name;
	
	private String imageName;
	
	private BigDecimal price;

	private byte[] productImage;

	private String quantity;

	private String status;
	
	@OneToMany(mappedBy="product")
	private List<Productimage> productImages;
	
	//bi-directional many-to-one association to Bid
	@OneToMany(mappedBy="product")
	private List<Bid> bids;

	//bi-directional many-to-one association to Category
	@ManyToOne
	@JoinColumn(name="CategoryId")
	private Category category;

	//bi-directional many-to-one association to Deal
	@ManyToOne
	@JoinColumn(name="DealId")
	private Deal deal;

	//bi-directional many-to-one association to Shop
	@ManyToOne
	@JoinColumn(name="ShopId")
	private Shop shop;

	
	//bi-directional many-to-one association to Sale
	@OneToOne(fetch = FetchType.LAZY, cascade=ALL)
	@JoinColumn(name="id")
	private Sale sale;

	public Product() {
		setId(UUID.randomUUID().toString());
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getBrand() {
		return this.brand;
	}

	public void setBrand(String brand) {
		this.brand = brand;
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getCreatedDateInShop() {
		return this.createdDateInShop;
	}

	public void setCreatedDateInShop(Date createdDateInShop) {
		this.createdDateInShop = createdDateInShop;
	}

	public Date getLastModifiedDate() {
		return this.lastModifiedDate;
	}

	public void setLastModifiedDate(Date lastModifiedDate) {
		this.lastModifiedDate = lastModifiedDate;
	}

	public Date getManufacturedDate() {
		return this.manufacturedDate;
	}

	public void setManufacturedDate(Date manufacturedDate) {
		this.manufacturedDate = manufacturedDate;
	}

	public Date getExpiryDate() {
		return expiryDate;
	}

	public void setExpiryDate(Date expiryDate) {
		this.expiryDate = expiryDate;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getImageName() {
		return imageName;
	}

	public void setImageName(String imageName) {
		this.imageName = imageName;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public byte[] getProductImage() {
		return this.productImage;
	}

	public void setProductImage(byte[] productImage) {
		this.productImage = productImage;
	}

	public String getQuantity() {
		return this.quantity;
	}

	public void setQuantity(String quantity) {
		this.quantity = quantity;
	}

	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public List<Productimage> getProductImages() {
		return productImages;
	}

	public void setProductImages(List<Productimage> productImages) {
		this.productImages = productImages;
	}

	public List<Bid> getBids() {
		return this.bids;
	}

	public void setBids(List<Bid> bids) {
		this.bids = bids;
	}

	public Bid addBid(Bid bid) {
		getBids().add(bid);
		bid.setProduct(this);

		return bid;
	}

	public Bid removeBid(Bid bid) {
		getBids().remove(bid);
		bid.setProduct(null);

		return bid;
	}

	public Category getCategory() {
		return this.category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public Deal getDeal() {
		return this.deal;
	}

	public void setDeal(Deal deal) {
		this.deal = deal;
	}

	public Shop getShop() {
		return this.shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}

	public Sale getSale() {
		return this.sale;
	}

	public void setSales(Sale sale) {
		this.sale = sale;
	}

	@Transient
	public boolean isBiddable(){
		boolean biddable;
		
		String dealtemp = this.deal.getDealType();
		
		if(this.deal.getDealType().equals("Auction Sale"))
		{
			biddable = true;
			System.out.print(dealtemp);
		}
		else
		{
			biddable = false;
		}
			
		return biddable;
	}

}